package top.infopub.mgr.mgc.web;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import top.infopub.generic.GenericController;
import top.infopub.mgr.common.page.ParamPage;
import top.infopub.mgr.common.vo.RspVo;
import top.infopub.mgr.mgc.domain.MsgTaskDomain;
import top.infopub.mgr.mgc.service.MsgTaskService;
import top.infopub.mgr.mgc.vo.MsgTaskVo;

import com.github.pagehelper.Page;


/**
 * 消息任务查询控制层
 * @author Awoke
 * @version 2018年11月8日
 * @see MsgTaskController
 * @since
 */
@Controller
@RequestMapping("/msgTask")
public class MsgTaskController extends GenericController {

    @Autowired
    private MsgTaskService msgTaskService;

    /** DEL_FLAG  0：可用  1：删除（不可用） **/
    /**可用*/
    private static final Integer DEL_ENABLE = 0;

    /** 消息类型  1： 短信 2：邮件 **/
    /**短信*/
    private static final Integer TYPE_MESSAGE = 1;

    /**邮箱*/
    private static final Integer TYPE_EMAIL = 2;

    /**
     * 进入用户已发邮件查询
     * @return
     */
    @RequestMapping("/email/list")
    public String emailList() {
        return "mgc/laymsg-task-email-list";
    }

    /**
     * 查询用户已发邮件
     * @return
     */
    @RequestMapping("/email/query")
    public @ResponseBody RspVo<MsgTaskDomain> queryEmail(MsgTaskVo msgTaskVo,
                                                              ParamPage paramPage) {
        Page<MsgTaskDomain> page = new Page<MsgTaskDomain>();
        page.setPageNum(paramPage.getPage());
        page.setPageSize(paramPage.getLimit());
        msgTaskVo.setDelFlag(DEL_ENABLE);
        msgTaskVo.setMsgType(TYPE_EMAIL);
        Page<MsgTaskDomain> pageList = msgTaskService.selectPageByVo(page, msgTaskVo);
        return RspVo.getSuccessResponse(pageList.getTotal(), pageList.getResult());
    }

    /**
     * 进入用户已发短信查询
     * @return
     */
    @RequestMapping("/message/list")
    public String messageList() {
        return "mgc/laymsg-task-message-list";
    }

    /**
     * 查询用户已发短信
     * @return
     */
    @RequestMapping("/message/query")
    public @ResponseBody RspVo<MsgTaskDomain> queryMessage(MsgTaskVo msgTaskVo,
                                                                ParamPage paramPage) {
        Page<MsgTaskDomain> page = new Page<MsgTaskDomain>();
        page.setPageNum(paramPage.getPage());
        page.setPageSize(paramPage.getLimit());
        msgTaskVo.setDelFlag(DEL_ENABLE);
        msgTaskVo.setMsgType(TYPE_MESSAGE);
        // dao层处理成 排除短信验证码
        msgTaskVo.setTemplateCode("excludeSmsVCode");
        Page<MsgTaskDomain> pageList = msgTaskService.selectPageByVo(page, msgTaskVo);
        return RspVo.getSuccessResponse(pageList.getTotal(), pageList.getResult());
    }

    /**
     * 进入用户发送短信验证码查询
     * @return
     */
    @RequestMapping("/messageCheck/list")
    public String messageCheckList() {
        return "mgc/laymsg-task-messageCheck-list";
    }

    /**
     * 查询用户发送短信验证码
     * @return
     */
    @RequestMapping("/messageCheck/query")
    public @ResponseBody RspVo<MsgTaskDomain> queryMessageCheck(MsgTaskVo msgTaskVo,
                                                                     ParamPage paramPage) {
        Page<MsgTaskDomain> page = new Page<MsgTaskDomain>();
        page.setPageNum(paramPage.getPage());
        page.setPageSize(paramPage.getLimit());
        msgTaskVo.setDelFlag(DEL_ENABLE);
        msgTaskVo.setMsgType(TYPE_MESSAGE);
        // 短信验证码编号
        msgTaskVo.setTemplateCode("SMS_V_CODE");
        Page<MsgTaskDomain> pageList = msgTaskService.selectPageByVo(page, msgTaskVo);
        return RspVo.getSuccessResponse(pageList.getTotal(), pageList.getResult());
    }

}
